package com.farm.shiro.authc.credential;

import com.farm.common.util.BcryptUtils;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.RememberMeAuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

import java.util.Arrays;

/**
 * BcryptCredentialsMatcher
 *
 * @author ctidy
 * @since 2021/1/7
 */
public class BcryptCredentialsMatcher extends SimpleCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        String passwordIn = String.valueOf((((UsernamePasswordToken) token)).getPassword());  // 前端传来的密码
        String passwordDB = info.getCredentials().toString();                                 // 数据库中的密码（密文）
        return BcryptUtils.match(passwordIn, passwordDB);
    }

}
